-- damage
-- create by panyl
-- 道具：  固定伤害

return {
    apply = function(source, target, classId, value)
        -- 固定伤害

        -- 传入攻击者信息
        local assailantInfo = {};
        local pos = source["pos"];
        if pos then
            assailantInfo = {
                ["property_id"] = classId,
                ["pos"]         = pos,
            };
        else
            assailantInfo = {
                ["property_id"] = classId,
            };
        end

        -- 计算最终伤害
        local damage = PropertyM.calcFinalDamage(source, target, classId, value);

        local args = {["class_id"] = classId, ["target"] = target,};

        -- 可能有额外的伤害目标
        local targets = { target, };

        local props = PropM.fetchProps(source, "pro_ranged_damage");
        for _, prop in ipairs(props) do
            targets = PropM.trigger(source, prop[1], prop[2], args);
        end

        -- 击杀掉落物品
        local isDrop = ItemM.query(classId, "apply") == "damage_and_drop";

        -- 造成伤害
        for _, monster in pairs(targets) do
            CombatM.doDamage(source, monster, damage, 0, isDrop, { assailantInfo = assailantInfo, });
        end

        -- 杀敌概率直接获得奖励
        props = PropM.fetchProps(source, "kill_get_item2");
        for _, prop in ipairs(props) do
            PropM.trigger(source, prop[1], prop[2], args);
        end

        if target.type ~= OBJECT_TYPE_USER then
            -- 抛出使用道具攻击事件
            local eventArgs = {
                ["classId"] = classId,
                ["target"] = target,
                ["source"] = source,
            }
            if #targets > 1 then
                eventArgs["moreTarget"] = targets;
            end

            EventMgr.fire(event.PROPERTY_ATTACK, eventArgs);
        end
    end,
};
